var Battle = require('./battle');
function BattleService(){
    this.battles = {};
}

BattleService.prototype.newBattle = function(){
    var battleId = 0;
    while(this.battles.hasOwnProperty(battleId)){
        battleId = Math.floor((Math.random() * 65535));
    };
    this.battles[battleId] = new Battle(battleId);
    return this.battles[battleId];
};

BattleService.prototype.hasBattle = function(battleId){
    return this.battles.hasOwnProperty(battleId);
};

BattleService.prototype.getBattle = function(battleId){
    return this.battles[battleId];
};

BattleService.prototype.delBattle = function(battleId){
    if(!this.hasBattle(battleId))
        delete this.battles[battleId];
};

module.exports= BattleService;